package com.fanfanwang.ffw.app.ui.my;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.fanfanwang.ffw.app.AppManager;
import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.asynctask.SetPasswordAsyncTask;
import com.fanfanwang.ffw.app.base.BaseActivity;
import com.fanfanwang.ffw.app.bean.UserInfoBean;
import com.fanfanwang.ffw.app.common.StringUtils;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.tools.SharedPreferencesUtil;
import com.fanfanwang.ffw.app.widget.CommonTitleBar;

/**
 * 修改个人密码
 * @author Administrator
 *
 */
public class MyUpdatePwdAct extends BaseActivity {

	private CommonTitleBar commonTitleBar;
	private Activity mAct;
	private Intent mIntent;
	private Button confirm_btn_complete;
	private EditText nowPwd,newPwd,confirmPwd;
	private TextView nowAccount; 
	private TextView tv_now_account;
	public static IUpdatePwdable iUpdatePwdable;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initView();
		AppManager.getAppManager().addActivity(this);
		initData();
		setListener();
	}

	@Override
	public void initView() {
		// TODO Auto-generated method stub
		setContentView(R.layout.activity_my_update_pwd);
		mAct = this;
		commonTitleBar = (CommonTitleBar) findViewById(R.id.common_titlebar);
		nowAccount =(TextView)findViewById(R.id.now_account);
		tv_now_account =(TextView)findViewById(R.id.tv_now_account);
		nowPwd =(EditText)findViewById(R.id.et_now_pwd);
		newPwd =(EditText)findViewById(R.id.et_new_pwd);
		confirmPwd =(EditText)findViewById(R.id.et_confirm_pwd);
		confirm_btn_complete=(Button)findViewById(R.id.confirm_btn_complete);

	}

	@Override
	public void setListener() {
		commonTitleBar.setToolBarReturnOnclickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		confirm_btn_complete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String newP=newPwd.getText().toString();
				String confirmP=confirmPwd.getText().toString();
				if(newP.equals(confirmP))
				{
					String nowP=nowPwd.getText().toString();
					new SetPasswordAsyncTask(mAct, SharedPreferencesUtil.getInstance(mAct).getUsername(), nowP, newP).execute("");
				}else{
					ToastAlone.showToast(mAct, getResources().getString(R.string.new_not_equals_confirm), Toast.LENGTH_SHORT).show();
				}
			}
		});

	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		commonTitleBar.setCenterText(getString(R.string.update_pwd));
		commonTitleBar.setReturnVisible();
		if(!TextUtils.isEmpty(SharedPreferencesUtil.getInstance(mAct).getUsername())){
			tv_now_account.setText(SharedPreferencesUtil.getInstance(mAct).getUsername());
		}
		setInterface();
	}

	/*public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
		}
		return super.onKeyDown(keyCode, event);
	}
	 */
	public void setInterface(){
		iUpdatePwdable=new IUpdatePwdable() {

			@Override
			public void updatePwd() {
				// TODO Auto-generated method stub
				finish();
			}
		};
	}
	public interface IUpdatePwdable{
		public void updatePwd();
	}
}
